<template>
	<view class="edit-info">
		<uni-forms :modelValue="formData">
			<uni-forms-item label="用户名">
				<uni-easyinput placeholder="输入用户名" v-model="formData.username"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="头像">
				<!-- <image src="../../static/uni.png" mode="" class="upload"></image> -->
				<view class="example-body">
					<uni-file-picker v-model="imageValue" 
						fileMediatype="image" 
						mode="grid" 
						@select="select" 
						@progress="progress" 
						@success="success" 
						@fail="fail">
					</uni-file-picker>
				</view>
			</uni-forms-item>
		</uni-forms>
		<button :class="tp==0?'green':''" @click="confirm">确定</button>
	</view>
</template>

<script>
import { GetUserinfoAdmin,UpdateUserinfoAdmin } from '../../api';
	export default {
		data() {
			return {
				id:'',
				formData:{
					username:'',
					avatar:''
				},
				imageValue:[],
				tp:''
			};
		},
		onLoad(options) {
			console.log(options,'opt')
			if(options.id){
				this.id = options.id
				this.getUserinfoAdmin(options.id)
			}
			if(options.tp==0){
				console.log('55')
				this.tp = 0
				uni.setNavigationBarColor({
					frontColor:'#ffffff',
					backgroundColor:'#1afa29'
				})
			}
			
			
		},
		onBackPress(options) {
			console.log(options,'opt')
			if(options.from == 'navigateBack'){
				console.log('back')
			}
			
		},
		methods:{
			async getUserinfoAdmin(id) {
				const {data:res} = await GetUserinfoAdmin(id)
				console.log(res,'userinfo')
				this.imageValue.push({url:res.data.avatar})
				this.formData = res.data
			},
			async confirm(){
				const {data:res} = await UpdateUserinfoAdmin(this.id,this.formData)
				console.log(res,'update')
				if(res.status==0){
					uni.showModal({
						title:res.message,
						icon:'success',
						success() {
							let pages = getCurrentPages()
							let beforePage = pages[pages.length-2]
							beforePage.$vm.getAdminList()
						}
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.edit-info{
		padding: 20rpx;
		button{
			background: #1E90FF;
		}
		.green{
			background: #1afa29;
			color:#fff;
		}
	}
	.example-body{
		// margin: 20rpx 0;
		// padding-bottom: 10rpx;
		.uni-file-picker{
			width: 400rpx;
			// height: 200rpx;
		}
		.icon-del-box{
			width: 30rpx;
			height: 30rpx;
			.icon-del{
				width: 20rpx;
			}
			
		}
	}
</style>
